package com.kitty.record.kittyio.netty.server;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author SHEN
 * @Date 2021/2/7
 */
public class MyServerHandler extends SimpleChannelInboundHandler<String> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String s) throws Exception {

        System.out.println(ctx.channel().remoteAddress()+":"+s);
        ctx.channel().writeAndFlush("来自服务端口吐芬芳式的问候"+ UUID.randomUUID());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
